
package com.theme.passport.controller.app;

import com.theme.common.base.GenerateOrderNumUtils;
import com.theme.common.mvc.utils.PageUtils;
import com.theme.common.mvc.view.R;
import com.theme.passport.annotation.Login;
import com.theme.passport.controller.app.utils.AppContextUtil;
import com.theme.passport.entity.SysFeedbackEntity;
import com.theme.passport.entity.UserEntity;
import com.theme.passport.entity.theme.UserBuyEntity;
import com.theme.passport.service.SysFeedbackService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Date;
import java.util.List;
import java.util.Map;


/**
 * 反馈意见
 *
 * @author live
 * @email 870459550@qq.com
 * @date 2020-12-08 15:14:01
 */
@RestController
@RequestMapping("app/feedback")
public class FeedbackController {

    @Autowired
    private SysFeedbackService sysFeedbackService;

    @Login
    @GetMapping("/list")
    @ApiOperation("查询用户提交的反馈意见")
    public R list(@RequestParam Map<String, Object> params){
        UserEntity currentUser = AppContextUtil.getCurrentUser();
        params.put("userId",currentUser.getId() +"");
        PageUtils page = sysFeedbackService.queryPage(params);
        List<UserBuyEntity> list = (List<UserBuyEntity>) page.getList();
        page.setList(list);
        return R.ok().put("page", page);
    }

    @Login
    @PostMapping("/submit")
    @ApiOperation("用户提交上传反馈意见")
    public R submit(@RequestBody SysFeedbackEntity sysFeedback){
        UserEntity currentUser = AppContextUtil.getCurrentUser();
        sysFeedback.setUserId(currentUser.getId());
        sysFeedback.setNumber(GenerateOrderNumUtils.generateOrderNum());
        sysFeedback.setCreateTime(new Date());
        sysFeedback.setUpdateTime(new Date());
		sysFeedbackService.save(sysFeedback);
        return R.ok();
    }

}
